<?php
// +---------------------------------------------------------------------+
// | OneBase    | [ WE CAN DO IT JUST THINK ]                            |
// +---------------------------------------------------------------------+
// | Licensed   | http://www.apache.org/licenses/LICENSE-2.0 )           |
// +---------------------------------------------------------------------+
// | Author     | Bigotry <3162875@qq.com>                               |
// +---------------------------------------------------------------------+
// | Repository | https://gitee.com/Bigotry/OneBase                      |
// +---------------------------------------------------------------------+

namespace app\common\model;

/**
 * 帖子留言模型
 */
class ForumBbsComment extends ModelBase
{
    protected $insert = ['create_time'];





    /**
     * 连分类表
     */
    public function bbs(){
        return $this->belongsTo('ForumBbs','bbs_id','id');
    }

    /**
     * 连用户表
     */
    public function user(){
        return $this->belongsTo('Member','user_id','id');
    }
    /**
     * 连用户表
     */
    public function touser(){
        return $this->belongsTo('Member','uid','id');
    }
    /**
     * 连点赞表
     */
    public function fabulous(){
        return $this->hasMany('ForumBbsCommentFabulous','bbs_id','id');
    }

    public function  getZanCountAttr(){

        return count($this->fabulous);

    }


    /**
     * 时间自动完成
     */
    public function setCreateTimeAttr()
    {

        return TIME_NOW;
    }
    /**
     *是否点赞
     */
    public function zan($uid)
    {

       if(ForumBbsCommentFabulous::where(['user_id'=>$uid,'bbs_id'=>$this->id])->find()){
          return 1;
       }else{
           return 0;
       }
    }

    /**
     *是否关注
     */
    public function follow($uid)
    {

        if(ForumFollow::where(['user_id'=>$uid,'uid'=>$this->user_id])->find()){
            return 1;
        }else{
            return 0;
        }
    }


    public function  getContentAttr($value){
        if(isset($_REQUEST['lang']) && $_REQUEST['lang']!='zh-cn' &&  $_REQUEST['lang'] ){
            return   baidu_translate($value);
        }
        return $value;

    }
}
